package com.rxnetwork.sample.login;

import com.rxnetwork.sample.api.Api;
import com.rxnetwork.sample.api.ApiInterface;
import com.rxnetwork.sample.model.ListModel;
import com.rxnetwork.sample.mvp.BasePresenterImpl;
import com.rxnetwork.sample.utils.network.AppNetWorkListener;
import com.rxnetwork.sample.utils.network.AppNetWorkManager;

import java.util.List;

public class LoginPresenter extends BasePresenterImpl<LoginContract.MyView> implements LoginContract.Presenter {

    @Override
    public void login(final String userName, final String password) {
        AppNetWorkManager
                .getInstance()
                .setBaseUrl(Api.ZL_BASE_API)
                .getApi(AppNetWorkManager.observable(ApiInterface.class).getList("daily", 20, 0), new AppNetWorkListener<List<ListModel>>() {
                    @Override
                    public void onNetWorkError(Throwable e) {
                        mView.loginFailed("登入失败");
                    }

                    @Override
                    public void onNetWorkSuccess(List<ListModel> data) {
                        mView.loginSuccess("登入成功");
                    }
                });

        AppNetWorkManager
                .getInstance()
                .setBaseUrl(Api.TEST_URL)
                .getApi(AppNetWorkManager.observable(ApiInterface.class).getTestString("lol", 1, 20), new AppNetWorkListener<Object>() {
                    @Override
                    public void onNetWorkError(Throwable e) {
                        mView.loginFailed("请求失败-------String");
                    }

                    @Override
                    public void onNetWorkSuccess(Object data) {
                        mView.loginSuccess("请求成功-------String");
                    }
                });
    }
}
